package OurGame;

import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.Random;

import javax.swing.*;

public class Dude3 {
	int x, dx, y, nx, nx2, left, dy;
	Image still, jump, reverse;

	int ammo = 1000;

	static ArrayList bullets;// Holds number of bullets on screen

	ImageIcon s = new ImageIcon("Image/ngan.png");
	ImageIcon j = new ImageIcon("Image/ngan.png");
	ImageIcon l = new ImageIcon("Image/ngan.png");

	Timer time;
	
	public static ArrayList getBullets() {
		return bullets;
	}

	public Dude3(int _left) {
		// ImageIcon i = new ImageIcon("C:/Users/Public/Pictures/vanille1.png");

		x = 75;
		left = _left;
		nx = 0;
		nx2 = 685;
		y = 180;
		still = s.getImage();
		bullets = new ArrayList();
		time = new Timer(4789, new ActionListener() {

			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				fire();
			}
		});
		time.start();
	}

	public void fire()// Method to run when when fired
	{
		Random ran = new Random();
		System.out.println(bullets.size() + " " + ammo);
		if (ammo > 0) {
			ammo--;
			// Create a new bullet object and add it to
			// array "list" of all bullets on screen.
			Bullet z = new Bullet((left + 20), (y + 154 / 2),ran.nextInt(100));
			bullets.add(z);
		}
	}

	public void move() {
		if (dx > -1)
			dx = 1;
		left = left + dx;
		if (left == (500 - 88))
		{
			dx = -1;
		}
		if (left == 0)
		{
			dx = 1;
		}
	}

	public void move1() {
		 if (dx != -1) {
		 if (left + dx <= (700 - 88))
		 left += dx;
		 else {
		 // x = x + dx;
		 // nx2 = nx2 + dx;
		 // nx = nx + dx;
		 dx = -1;
		 left = left + dx;
		 }
		 }
		 else {
		 if (left + dx > 0)
		 left = left + dx;
		 else {
		 dx = 1;
		 left = left + dx;
		 }
		 }
//		if (dx != -1)
//		{
//			for (int i = 1; i <= (700 - 88); i++) {
//				left += i;
//			}
//			dx = -1;
//		}
//		else {
//			for (int i = 1; i <= (700 - 88); i++) {
//				left -= i;
//			}
//			dx = 1;
//		}
	}

	public int getX() {
		return x;
	}

	public int getY() {
		return y;
	}

	public int getnX() {
		return nx;
	}

	public int getnX2() {
		return nx2;
	}

	public int getdx() {
		return dx;
	}

	public Image getImage() {
		return still;
	}

	public void keyPressed(KeyEvent e) {
		int key = e.getKeyCode();
//		if (key == KeyEvent.VK_LEFT) {
//			dx = -1;
//			still = l.getImage();
//		}
//		if (key == KeyEvent.VK_RIGHT) {
//			dx = 1;
//			still = s.getImage();
//		}
//
//		if (key == KeyEvent.VK_SPACE) {
//			fire();
//		}
//
//		if (key == KeyEvent.VK_UP) {
//			dy = 1;
//			still = j.getImage();
//		}
	}

	public void keyReleased(KeyEvent e) {
		int key = e.getKeyCode();
//		if (key == KeyEvent.VK_LEFT)
//			dx = 0;
//		if (key == KeyEvent.VK_RIGHT)
//			dx = 0;
//		if (key == KeyEvent.VK_UP) {
//			dy = 0;
//			still = s.getImage();
//		}
	}
}